package cn.winstone.utils;

import cn.winstone.enums.StatusCodeEnum;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Winstone
 * @date 2020/7/28 - 7:49 下午
 */
public class FileUtils {
    public static List<String> getFilesURI(String path) {
        ArrayList<String> files = new ArrayList<>();
        try {
            File file = new File(path);
            System.out.println(path);
            File[] tempList = file.listFiles();

            for (int i = 0; i < tempList.length; i++) {
                if (tempList[i].isFile()) {
                    files.add(tempList[i].toString());
                }
            }
            return files;
        }catch (Exception e){
            ConsolePrint.serverErr(StatusCodeEnum.NOTFOUND);
        }
        return new ArrayList<>();
    }


    public static InputStream readFile(String path) {
        File file = new File(path);
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return inputStream;
    }
}
